<?php

namespace app\admin\model\learn;

use think\Db;
use think\Model;


class Must extends Model
{

    

    

    // 表名
    protected $name = 'learn_cate_course1';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'status_text',
        'grade_text',
        'learn_cate_id_text'
    ];

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
    }
    public function getLearnCateIdList()
    {
        return ['1' => __('Learncate.type 1'), '2' => __('Learncate.type 2'), '3' => __('Learncate.type 3'), '4' => __('Learncate.type 4')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function getGradeList()
    {
        return ['1' => __('小班'), '2' => __('中班'), '3' => __('大班'),'4' => __('一年级'), '5' => __('二年级'), '6' => __('三年级'), '7' => __('四年级'), '8' => __('五年级'), '9' => __('六年级'), '10' => __('初一年级'), '11' => __('初二年级'), '12' => __('初三年级'), '13' => __('高一年级'), '14' => __('高二年级'), '15' => __('高三年级')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getLearnCateIdTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['learn_cate_id']) ? $data['learn_cate_id'] : '');
        $list = $this->getLearnCateIdList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getGradeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getGradeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function learncourse()
    {
        return $this->belongsTo('app\admin\model\learn\Course', 'learn_course_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getNameById($id)
    {
        return Db::name('learn_course')->alias('c')
            ->join(['edu_learn_cate_course1 c1'],'c.id = c1.learn_course_id','left')
            ->where('c1.id', '=', $id)->value('c.name');
    }
}
